/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package chess;

import javax.swing.ImageIcon;
import javax.swing.JButton;
/**
 *
 * @author Alejandro
 */
public class Knight extends Token{
    
    public Knight (int column, int row, int color, JButton [][] board,
            Token [][] tokens){
        ImageIcon[] iconos = {new ImageIcon("src/imagenes/Scourge/abbadon-C50.gif")
                        ,new ImageIcon("src/imagenes/Legion/priestess-C50.gif")};
        this.setRow(row);
        this.setIcon(iconos);
        this.setColumn(column);
        this.setColor(color);
        this.board = board;
        this.setTokenOnBoard();
        this.tokens = tokens;
        this.setType("N");
    }

    @Override
    public void moveToken(int newColumn, int newRow){
        int F = this.getRow();
        int C = this.getColumn();
        boolean hit = tokens[newColumn][newRow] != null;
        enemy = hit && tokens[newColumn][newRow].getColor() != this.getColor();
        if (((newRow == F + 1 && Math.abs(newColumn - C) == 2) ||
                (newRow == F - 1 && Math.abs(newColumn - C) == 2)||
                (newColumn == C + 1 && Math.abs(newRow - F) == 2)||
                (newColumn == C - 1 && Math.abs(newRow - F) == 2))&& 
                (!hit || enemy)){
            board[C][F].setIcon(null);
            this.setRow(newRow);
            this.setColumn(newColumn);
            this.setTokenOnBoard();
            this.setCorrectMove(true);
        }
        else{
            this.setCorrectMove(false);
        }
    }
    
    private void setTokenOnBoard(){
        board[this.getColumn()][this.getRow()].setIcon(this.getIcon()[this.getColor()]);
    }
}
